home *** CD-ROM | disk | FTP | other *** search
- {RANDOM NUMBER GENERATOR GARY CURTIS NEWPORT
-
- PURPOSE : To generate a pseudorandom number in the open interval, (0,1).
-
- ALGORITHM : The linear congruential method is used. See G. Gordon,
- System Simulation, second edition, Prentice-Hall, 1978,
- pp. 128-129
-
- USE : The following global declaration is necessary:
-
- VAR seed : long_integer;
-
- Include RANDNUMS after program declarations. At the beginning
- of the program, insert the following:
-
- SET_RANDOM(seed);
-
- This seeds the random number generator, which can be called
- as needed, in the following way:
-
- x := RANDOM(seed);
-
- (Where x is any declared real variable.)
-
- }
-
- procedure
- SET_RANDOM ( VAR seed : long_integer);
-
- CONST
-
- m = 65535; { must be >= 0 and < 262139 }
-
- BEGIN {Set_Random}
-
- seed := CLOCK mod m
-
- END; {Set_Random}
-
- function
- RANDOM ( VAR seed : long_integer): real;
-
- CONST
-
- a = 11109; { See Daley, lecture notes, Computer Simulation, p. 19 }
- c = 13849; { for a derivation of these constants. }
- m = 65535;
-
- BEGIN {Random}
-
- seed := ((seed * a) + c) mod m;
- Random := seed/m
-
- END; {Random}
-